﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTOSingTowerMall;

namespace BLSingTowerMall
{
    public class StoreProcess
    {
        private DBSingTowerMallEntities db = new DBSingTowerMallEntities();

        public IQueryable<Store> getStores()
        {
            var stores = from s in db.Stores
                         join b in db.Blocks on s.BlockID equals b.BlockID
                         where b.Status != null
                         select s;
            return stores;
        }

        public IQueryable<Store> getStoresByCategory(string categoryName)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       join c1 in db.Categories on c.CategoryID equals c1.CategoryID
                                       where c1.CategoryName.ToUpper() == categoryName.ToUpper()
                                       select s;
            return stores;
        }

        public IQueryable<SubCategory> getSubCategoryList(string categoryName)
        {
            var list = from c in db.Categories
                       join c1 in db.SubCategories on c.CategoryID equals c1.CategoryID
                       where c.CategoryName.ToUpper() == categoryName.ToUpper()
                       select c1;
            return list;
        }

        public IQueryable<Store> getStoresBySubcategory(string SubCategoryName)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       where c.SubCategoryName.ToUpper() == SubCategoryName.ToUpper()
                                       select s;
            return stores;
        }

        public IQueryable<Store> getStoresByLevel(int Level)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       where b.Level == Level
                                       select s;
            return stores;
        }

        public IQueryable<Store> getStoresByLevel(int Level, string categoryName)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       join c1 in db.Categories on c.CategoryID equals c1.CategoryID
                                       where b.Level == Level &&
                                                    c1.CategoryName == categoryName
                                       select s;
            return stores;
        }

        public IQueryable<Store> getStoresByLevelAndCategory(int Level, string categoryName)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       join c1 in db.Categories on c.CategoryID equals c1.CategoryID
                                       where b.Level == Level &&
                                                    c1.CategoryName == categoryName
                                       select s;
            return stores;
        }

        public IQueryable<Store> getStoresByName(string StoreName)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       where s.StoreName == StoreName
                                       select s;
            return stores;
        }

        public IQueryable<int> getLevel()
        {
            IQueryable<int> Level = db.Levels.Select(m => m.Level1);
            return Level;
        }

        public IQueryable<Store> getStores(int? subcategoryID, int? categoryID)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       join c1 in db.Categories on c.CategoryID equals c1.CategoryID
                                       where c1.CategoryID == categoryID &&
                                       c.SubCategoryID == subcategoryID
                                       select s;
            return stores;
        }

        public IQueryable<Store> getStoresByCategoryID(int categoryID)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       join b in db.Blocks on s.BlockID equals b.BlockID
                                       join c in db.SubCategories on b.Type equals c.SubCategoryID
                                       join c1 in db.Categories on c.CategoryID equals c1.CategoryID
                                       where c1.CategoryID == categoryID
                                       select s;
            return stores;
        }

        public IQueryable<Store> Stores(string q)
        {
            IQueryable<Store> stores = from s in db.Stores
                                       where s.StoreName.Contains(q)
                                       select s;
            return stores;
        }
    }
}
